package com.zjk.storage.core.aspect.delete;

import com.zjk.storage.core.aspect.FileStorageAspect;
import com.zjk.storage.core.entity.BaseFileInfo;
import com.zjk.storage.core.provider.FileStorage;
import lombok.Getter;
import lombok.Setter;

import java.util.Iterator;

@Getter
@Setter
public class DeleteAspectChain {
    private DeleteAspectChainCallback callback;
    private Iterator<FileStorageAspect> aspectIterator;
    public DeleteAspectChain(Iterable<FileStorageAspect> aspects, DeleteAspectChainCallback callback) {
        this.aspectIterator = aspects.iterator();
        this.callback = callback;
    }

    public boolean next(BaseFileInfo fileInfo, FileStorage fileStorage) {
        if (aspectIterator.hasNext()) {
            return aspectIterator.next().deleteAround(fileInfo, fileStorage, this);
        }
        return callback.run(fileInfo, fileStorage);
    }
}
